package com.juttec.freshbird.pet;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.view.WindowManager;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.juttec.freshbird.pet.fragment.ContentFragment;
import com.juttec.freshbird.pet.fragment.LeftFragment;

public class MainActivity extends SlidingFragmentActivity {

    private static final String CONTENT_FRAGMENT ="content_fragment" ;
    private static final String LEFT_FRAGMENT = "left_fragment";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置屏幕没有标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置弹出输入法时，屏幕不会上移
//        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(R.layout.activity_main);
        //获得屏幕管理者
        WindowManager windowManager = this.getWindowManager();
        //屏幕管理者调用默认展示方法可以获得宽度和高度
        //此处需设置侧边栏展示宽度，故获得宽度
        int width = windowManager.getDefaultDisplay().getWidth();
        int length = (int) (width*0.618);

        //设置侧边栏布局
        setBehindContentView(R.layout.left_menu);
        //获得侧边栏对象
        SlidingMenu slidingMenu = getSlidingMenu();
        //设置第二侧边栏
//        slidingMenu.setSecondaryMenu();
        //设置侧边栏打开方向
        slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
        //设置打开方式
        //打开方式共有四种：1全屏触摸打开 2屏幕左边触摸打开 3屏幕右边触摸打开 4禁止触摸打开
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        //设置侧边栏显示宽度
        slidingMenu.setBehindOffset(length);
        initFragment();
    }

    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.rl_left_menu, new LeftFragment(), LEFT_FRAGMENT);
        transaction.replace(R.id.fl_content, new ContentFragment(), CONTENT_FRAGMENT);
        transaction.commit();
    }
    public LeftFragment getLeftMenuFragment() {
        FragmentManager fg = getSupportFragmentManager();
        LeftFragment fragment = (LeftFragment) fg.findFragmentByTag(LEFT_FRAGMENT);
        return fragment;
    }
}
